<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let Person = function(name){
      this.name = name
    }

    Person.prototype.getName = function(){
      return this.name
    }

    function objectFactory(){
      var obj = new Object(),
          Constructor = [].shift.call(arguments)
      console.log("Constructor ==> ", Constructor);
      console.log("Constructor.prototype ==> ", Constructor.prototype);
      console.log("Object.prototype ==> ", Object.prototype);
      console.log(Object.prototype === obj.__proto__);
      console.log(Constructor.prototype === obj.__proto__);

      obj.__proto__ = Constructor.prototype
      var ret = Constructor.apply(obj, arguments)
      console.log("obj ==> ", obj);
      // console.log("ret ==> ", ret);
      return typeof ret === 'object' ? ret : obj
    }

    var a = objectFactory(Person, 'nathan')
    console.log("a ==> ", a);
    console.log(a.name);
    console.log(a.getName());

    console.log(Object.getPrototypeOf(a) === Person.prototype);

    var b = new Person('nathan')
    console.log("b ==> ", b.name);
    console.log("b ==> ", b.getName());


    console.log("-----------------------------------");

    var c = new Object()
    console.log("c ==> ", c);
    console.log(Object.getPrototypeOf(c) === Object.prototype);
    console.log(c.__proto__ === Object.prototype);

    console.log('-------------------------');

    var X = function(){}
    X.prototype = { age: 15 }

    var Y = function(){}
    Y.prototype = new X()

    var y = new Y()
    console.log(y.age);
    console.log(y.age);

    console.log('---------------------');

    class Animal{
      constructor(name){
        this.name = name
      }
      getName(){
        return this.name
      }
    }

    class Dog extends Animal{
      constructor(name){
        super(name)
      }
      speak(){
        return 'wooooooooo'
      }
    }

    var dog = new Dog('nathan')
    console.log(dog.getName(), dog.speak());
    

  </script>
</body>
</html>